package com.gdupt.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gdupt.entity.CustomerInfo;
import com.gdupt.entity.vo.ResponseData;
import com.gdupt.service.ICustomerInfoService;
import com.gdupt.service.impl.CustomerInfoServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 客户信息 客户信息 前端控制器
 * </p>
 *
 * @author gdupt
 * @since 2018-11-21
 */
@RestController
@RequestMapping("/customer-info")
public class CustomerInfoController {
    @Autowired
    private ICustomerInfoService customerInfoService;
    @RequestMapping("/client")
    public ResponseData list(Page page,@RequestParam(value = "search",required = false) String search) {
       List<CustomerInfo> list = customerInfoService.selectCustomerInfoPage(page,search);
        return ResponseData.okData(page.getTotal(),list);
        }
        @RequestMapping("/detail/{id}")
        public ResponseData getById(@PathVariable(value = "id") Integer id){
            System.out.println(id);
            CustomerInfo byId = customerInfoService.getById(id);
            System.out.println(byId);
            return ResponseData.okSingleData(byId);
    }
    @PostMapping("/save")
    public ResponseData save(CustomerInfo customerInfo){
        System.out.println(customerInfo);
        boolean flg;
        flg = customerInfoService.updateById(customerInfo);
        System.out.println(flg);
        if (flg){
            return ResponseData.okMsg("编辑成功");
        }
        else return ResponseData.okMsg("编辑失败");
    }
}

